using UnityEngine;
using System.Collections;

public class FlashColor : MonoBehaviour {
	
	public bool staticObject;
	private CharacterManager player;
	
	// Use this for initialization
	IEnumerator Start () 
	{
		player = GameObject.FindGameObjectWithTag("Player").GetComponent<CharacterManager>();
		
		StartCoroutine("SwitchColor");
		
		if(!staticObject)
		{
			yield return new WaitForSeconds(10);

			player.specialCube = false;
			renderer.material.color = player.getColorManager().myColor;

			Destroy(this);

			gameObject.SendMessage("finishSpecialCube",SendMessageOptions.DontRequireReceiver);
		}
	}

	IEnumerator SwitchColor()
	{
		yield return new WaitForSeconds(0.1f);
		Color color = new Color(Random.Range(0.0f,1.0f),Random.Range(0.0f,1.0f),Random.Range(0.0f,1.0f),renderer.material.color.a);
		renderer.material.color = color;
		StartCoroutine("SwitchColor");
	}
	
	void OnResume()
	{
		if(!staticObject)
		StartCoroutine(resumeMode());
		
		StartCoroutine("SwitchColor");

	}
	
	IEnumerator resumeMode()
	{
		yield return new WaitForSeconds(5);
		player.specialCube = false;
		renderer.material.color = player.getColorManager().myColor;
		Destroy(this);
		gameObject.SendMessage("finishSpecialCube",SendMessageOptions.DontRequireReceiver);
	}
}

